package com.bieyang.anjia.net;

import java.util.Map;

import com.bieyang.anjia.refresh.BasicHandler;
import com.bieyang.anjia.refresh.Response;
import com.bieyang.anjia.utils.LogUtils;
import com.bieyang.anjia.viewmodel.BaseViewModel;
import com.http.volley.Request;
import com.http.volley.VolleyError;
import com.http.volley.VolleyClient.VolleyResponseHandler;

/*************************文件信息*****************************
 * 模块名：AnJia
 * 文件名：ResponseHandler.java 
 * 创建者：刘松
 * 创建日期： 2015年1月7日 
 * 功能描述：
 ***********************************************************/
public class ResponseHandler implements VolleyResponseHandler {

	@Override
	public void handleResponse(Request<? extends Object> req, Object response, Map<String, String> reqHeader) {
		LogUtils.LogProtocol(response.toString());
		Response tag = (Response) req.getTag();
		tag.code = 0;
		tag.status = 0;
		tag.output = response;
		for (BaseViewModel viewModel : BasicHandler.handlers) {
			viewModel.handle(tag);
		}
	}

	@Override
	public void handleResponseError(Request<? extends Object> req, VolleyError error) {
		LogUtils.LogProtocol(error.toString());
		Response tag = (Response) req.getTag();
		tag.code = 1;
		tag.status = 0;
		tag.output = null;
		for (BaseViewModel viewModel : BasicHandler.handlers) {
			viewModel.handle(tag);
		}
	}
}
